

/** 
 * 通用类
 * @author  zhouhl
 * @version 1.0
 */

(function ($) {


	var Common = $.Common = $.Class.extend({
		init: function (element, options) {
			var self = this;
			this.t_time = 0;
			this.pre_time = 0;
			this.history_page = "";
			this.queue_page = [];
			this.queue_page_id = [];
			this.maxHouZhui = "";

			this.mask = null;
			this.mask_flag = false;

			this.wechat_queue_page = [];
		},

		/**
		 * 没有数据的显示域
		 * Create By：   zhouhl          
		 * @param title        显示的内容
		 * @param loadClass    显示的class
		 */
		nodata: function (opts) {
			var self = this;
			var default_opts = {
				loadClass: "mui-loader-show gray",
				title: "当前还没有任何数据哦"
			}

			var optsx = self.extend(
				self.extend(
					optsx || {}, default_opts
				),
				opts);


			var waitShow = '<div class="' + optsx.loadClass + '">' + optsx.title + '</div>';
			return waitShow;
		},

		/**
		 * 没有网络的显示 
		 * Create By：   zhouhl          
		 * @param loadClass      显示的class
		 * @param back           返回的函数
		 * @param refresh        刷新的函数  
		 * @param showWaiting    刷新是否显示等待框
		 * @param waitingTitle   属性时等待的标题
		*/
		nonet: function (opts) {
			var self = this;
			var default_opts = {
				loadClass: "mui-loader-show gray",
				back: function () {
					self.back();
				},
				refresh: function (showWaiting, waitingTitle) {
					self.refresh(showWaiting, waitingTitle);
				},
				showWaiting: true,
				waitingTitle: ''
			}

			var optsx = self.extend(
				self.extend(
					optsx || {}, default_opts
				),
				opts);

			var nonetShow = '<div class="' + optsx.loadClass + ' nonet"><li><h3>由于网络原因，该页面无法正常显示，您可以</h3></li><li><h3><a type="refresh">重新加载该页面</a></h3></li><li><h3>或者</h3></li><li><h3><a type="back" >返回上一页面</a></h3></li></div>';

			setTimeout(
				function () {
					mui(".nonet").on('tap', 'a', function (e) {
						if (this.getAttribute("type") == "back") {
							optsx.back();
						}
						else {
							optsx.refresh(optsx.showWaiting, optsx.waitingTitle);
						}


					});
				}, 500
			);

			return nonetShow;
		},


		/**
		 * 操作异常
		 * Create By：   zhouhl          
		 * @param loadClass      显示的class
		 * @param back           返回的函数
		 * @param refresh        刷新的函数  
		 * @param showWaiting    刷新是否显示等待框
		 * @param waitingTitle   属性时等待的标题
		*/
		errorPage: function (opts) {
			var self = this;
			var default_opts = {
				loadClass: "mui-loader-show gray",
				back: function () {
					self.back();
				},
				refresh: function (showWaiting, waitingTitle) {
					self.refresh(showWaiting, waitingTitle);
				},
				showWaiting: true,
				waitingTitle: ''
			}

			var optsx = self.extend(
				self.extend(
					optsx || {}, default_opts
				),
				opts);

			var nonetShow = '<div class="' + optsx.loadClass + ' nonet"><li><h3>数据加载出现了一点小异常，您可以</h3></li><li><h3><a type="refresh">重新加载该页面</a></h3></li><li><h3>或者</h3></li><li><h3><a type="back" >返回上一页面</a></h3></li></div>';

			setTimeout(
				function () {
					mui(".nonet").on('tap', 'a', function (e) {
						if (this.getAttribute("type") == "back") {
							optsx.back();
						}
						else {
							optsx.refresh(optsx.showWaiting, optsx.waitingTitle);
						}


					});
				}, 500
			);

			return nonetShow;
		},




		/**
		 * 开启遮罩
		 */
		startMask: function (ele) {
			//jQuery("#my-modal-loading").modal("open"); 
			if (!ele) {
				ele = "body";
			}
			jQuery(ele).waitMe({
				effect: "roundBounce",
				text: '载入中...',
				bg: 'rgba(255,255,255,0.7)',
				color: '#000',
				sizeW: '',
				sizeH: '',
				source: 'waitMe/img.svg'
			});

		},
		/**
		 * 关闭遮罩
		 */
		endMask: function (ele) {
			//jQuery("#my-modal-loading").modal("close"); 

			if (!ele) {
				ele = "body";
			}

			jQuery(ele).waitMe("hide");
		},


		/**
		* 点击按钮后发生错误的提示
		* Create By：          zhouhl          
		*/
		endActionError: function (opts) {
			var self = this;
			mui.toast('操作发生错误,请稍后再试');
			self.endAction(opts);
		},

		/**
		* 点击按钮后网络出现异常
		* Create By：          taoxh          
		* Create Date：     2015----------------------------09-19
		*/
		endActionNonet: function (opts) {
			var self = this;
			mui.toast('您的网络出现异常,请稍后再试');
			self.endAction(opts);
		},






		/**
		 * 微信跳转
		 * Create By：           zhouhl         
		 * @param url      跳转的url
		 * @param p_hidden_num  返回是否删除之前的url   
		 */
		forward_wechat: function (opts) {
			var self = this;

			setTimeout(
				function () {
					self.startMask()
				}, 0);

			if (opts.url.substr(opts.url.length - 4) == 'html') {
				window.location.href = opts.url + '?sa=' + Math.random();
			} else {
				window.location.href = opts.url + '&sa=' + Math.random();
			}
		},

		/**
		 * 获取url参数
		 * @param {*} name 
		 */
		getQueryString : function (name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
			var r = window.location.search.substr(1).match(reg);
			if (r != null) return unescape(r[2]);
			return null;
		}
	});


	$.fn.common = function (options) {
		var self = this;
		return new Common(self, options);
		//return this;
	}
}(mui))


